<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>管理用户 - 听到微笑的博客</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/style.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/font-awesome.min.css">
<link rel="apple-touch-icon-precomposed" href="${pageContext.request.contextPath }/images/icon/icon.png">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/images/icon/favicon.ico">
<script src="${pageContext.request.contextPath }/js/jquery-2.1.4.min.js"></script>
</head>

<body class="user-select">
	<section class="container-fluid">
		<jsp:include page="common/top.jsp"></jsp:include>
		<div class="row">
			<jsp:include page="common/left.jsp"></jsp:include>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
				<h1 class="page-header">管理</h1>
				<div class="table-responsive">
					<table class="table table-striped table-hover">
						<thead>
							<tr>
								<th>
									<span class="glyphicon glyphicon-th-large"></span>
									<span class="visible-lg">ID</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-user"></span>
									<span class="visible-lg">用户名</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-envelope"></span>
									<span class="visible-lg">邮箱</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-bookmark"></span>
									<span class="visible-lg">昵称</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-time"></span>
									<span class="visible-lg">创建时间</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-align-justify"></span>
									<span class="visible-lg">账户状态</span>
								</th>
								<th>
									<span class="glyphicon glyphicon-pencil"></span>
									<span class="visible-lg">操作</span>
								</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${pageView.items }" var="item" varStatus="s">
								<tr>
									<td>${s.count }</td>
									<td>${item.username }</td>
									<td>${item.email }</td>
									<td>${item.name }</td>
									<td>${item.stringCreatetime }</td>
									<td>
										<c:choose>
											<c:when test="${item.activation==0 }">
												未激活
											</c:when>
											<c:when test="${item.activation==1 }">
												正常使用
											</c:when>
											<c:when test="${item.activation==-1 }">
												禁用
											</c:when>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${item.activation==0 }">
												账户未激活
											</c:when>
											<c:when test="${item.activation==1 }">
												<a onclick="reverseUserStatus(${item.id},1)">禁用</a>
											</c:when>
											<c:when test="${item.activation==-1 }">
												<a onclick="reverseUserStatus(${item.id},-1)">解除禁用</a>
											</c:when>
										</c:choose>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<footer class="message_footer">
						<nav>
							<ul class="pagination pagenav">
								<c:choose>
									<c:when test="${pageView.currentPage>1 }">
										<li>
											<a aria-label="Previous" href="${pageContext.request.contextPath }/manage-user.html?currentPage=${pageView.currentPage-1}&countItem=${pageView.countItem}">
												<span aria-hidden="true">&laquo;</span>
											</a>
										</li>
									</c:when>
									<c:otherwise>
										<li class="disabled">
											<a aria-label="Previous">
												<span aria-hidden="true">&laquo;</span>
											</a>
										</li>
									</c:otherwise>
								</c:choose>
								<c:choose>
									<c:when test="${pageView.countPage>5 }">
										<c:choose>
											<c:when test="${pageView.currentPage>3 and pageView.currentPage<pageView.countPage-2 }">
												<li>
													<a href="#">...</a>
												</li>
												<c:forEach begin="${pageView.currentPage-2 }" end="${pageView.currentPage+2 }" var="i">
													<c:choose>
														<c:when test="${i==pageView.currentPage }">
															<li class="active">
																<a href="#">${i }</a>
															</li>
														</c:when>
														<c:otherwise>
															<li>
																<a href="${pageContext.request.contextPath }/manage-user.html?currentPage=${i}&countItem=${pageView.countItem}">${i }</a>
															</li>
														</c:otherwise>
													</c:choose>
												</c:forEach>
												<li>
													<a href="#">...</a>
												</li>
											</c:when>
											<c:when test="${pageView.currentPage<=3}">
												<c:forEach begin="1" end="5" var="i">
													<c:choose>
														<c:when test="${i==pageView.currentPage }">
															<li class="active">
																<a href="#">${i }</a>
															</li>
														</c:when>
														<c:otherwise>
															<li>
																<a href="${pageContext.request.contextPath }/manage-user.html?currentPage=${i}&countItem=${pageView.countItem}">${i }</a>
															</li>
														</c:otherwise>
													</c:choose>
												</c:forEach>
												<li>
													<a href="#">...</a>
												</li>
											</c:when>
											<c:when test="${pageView.currentPage>=pageView.countPage-2}">
												<li>
													<a href="#">...</a>
												</li>
												<c:forEach begin="${pageView.countPage-5 }" end="${pageView.countPage }" var="i">
													<c:choose>
														<c:when test="${i==pageView.currentPage }">
															<li class="active">
																<a href="#">${i }</a>
															</li>
														</c:when>
														<c:otherwise>
															<li>
																<a href="${pageContext.request.contextPath }/manage-user.html?currentPage=${i}&countItem=${pageView.countItem}">${i }</a>
															</li>
														</c:otherwise>
													</c:choose>
												</c:forEach>
											</c:when>
										</c:choose>
									</c:when>
									<c:otherwise>
										<c:forEach begin="1" end="${pageView.countPage }" var="i">
											<c:choose>
												<c:when test="${i==pageView.currentPage }">
													<li class="active">
														<a href="#">${i }</a>
													</li>
												</c:when>
												<c:otherwise>
													<li>
														<a href="${pageContext.request.contextPath }/manage-user.html?currentPage=${i}&countItem=${pageView.countItem}">${i }</a>
													</li>
												</c:otherwise>
											</c:choose>
										</c:forEach>
									</c:otherwise>
								</c:choose>
								<c:choose>
									<c:when test="${pageView.currentPage<pageView.countPage }">
										<li>
											<a href="${pageContext.request.contextPath }/manage-user.html?currentPage=${pageView.currentPage+1}&countItem=${pageView.countItem}" aria-label="Next">
												<span aria-hidden="true">&raquo;</span>
											</a>
										</li>
									</c:when>
									<c:otherwise>
										<li class="disabled">
											<a href="#" aria-label="Next">
												<span aria-hidden="true">&raquo;</span>
											</a>
										</li>
									</c:otherwise>
								</c:choose>
							</ul>
						</nav>
					</footer>
				</div>
			</div>
		</div>
	</section>
	<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath }/js/admin-scripts.js"></script>
	<script>
		//status==1表示原先为激活状态,status==-1表示原先为作废状态
		function reverseUserStatus(userId,status){
			var confirmStr="";
			if(status==1){
				confirmStr="此次操作将导致该用户无法登录，继续操作吗？";
			}else{
				confirmStr="此次操作将使得该用户重新获得登录权限，继续操作吗？";
			}
			if(confirm(confirmStr)){
				$.post(
					"${pageContext.request.contextPath}/user/reverse-status.action",
					{"userId":userId},
					function(data){
						if(data.status=="ok"){
							window.location.reload();
						}
					},
					"json"
				);
			}
		}
		$(function () {
			$("#user").addClass('active');
		});
	</script>
</body>
</html>
